package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

public class UdpDictionaryServer extends UdpEchoServer {
    private HashMap<String,String> hashMap=new HashMap<>();
    public UdpDictionaryServer(int port) throws SocketException {
        super(port);

        hashMap.put("cat","小猫");
        hashMap.put("dog","小狗");
        hashMap.put("chicken","鸡鸡");//还可以添加无数个这个样的键值对
    }
//    词典服务器,继承下来有些方法需要从写.

    @Override
    public String process(String request) {
//        参数是一个英文单词,返回值是对应的汉语
        return hashMap.getOrDefault(request,"您查找的单词不存在!");
    }

    public static void main(String[] args) throws IOException {
        UdpDictionaryServer server=new UdpDictionaryServer(6666);
        server.start();
    }
}
